package com.example.store2024.controller;

import com.example.store2024.model.Good;
import com.example.store2024.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Controller
public class DetaialController {
    private GoodService goodService;

    @Value("${store.static.site}")
    private String siteUrl;
    @Autowired
    public void setGoodService(GoodService goodService) {
        this.goodService = goodService;
    }

    /**
     * 跳转到商品详情页
     * id 商品详情页
     * */
    @GetMapping("/detail")
    public  String detail(Integer id, Map<String,Object> model){
        Objects.requireNonNull(id);//不允许为空

        Good good = this.goodService.findGoodById(id);

        List<String> imgs= good.getStringImagerArray();

        model.put("good",good);
        model.put("site",siteUrl);

        return "detail";
    }
}
